package service

import (
	"git.huoys.com/block_chain/mall/internal/shop/model"
	"git.huoys.com/block_chain/mall/internal/shop/repository"
	userSer "git.huoys.com/block_chain/mall/internal/user/service"
	"git.huoys.com/block_chain/mall/pkg/log"
)

type ShopService interface {
	// 添加商品类别
	AddClass(name string) (cid uint64, err error)
	// 添加商品
	AddGood(goods model.Goods, uid uint64) (goodId uint64, err error)
	// 删除商品
	DelGood(goodId uint64) (err error)
	// 修改商品属性
	SetGood(good model.Goods) (err error)
	// 根据分类查找商品
	GetGoodByClass(classId, lastId, limit uint64) (goodList []*model.GoodsList, count uint64, err error)
	// 获取分类前几的商品
	GetGoodSByClassSorting(num uint64) (goodList []*model.GoodsList, err error)
	// 获取用户所有商品
	GetUserGoods(uid uint64) (goods []*model.GoodsList, err error)
	// 获取商品详细信息
	GetGoodInfo(goodsId uint64) (imgs []model.ImgS, goods model.Goods, err error)
	// 上传图片地址
	UploadGoodImg(goodId uint64, url string, isMaster bool) (err error)
	// 删除图片地址
	DelGoodImg(goodId, imgId uint64) (err error)

	// 创建订单
	AddOrder(uid, oid uint64) (id uint64, err error)
	// 查询用户订单列表 可以分类
	GetOrderList(uid uint64, status uint64) (orders []model.Order, err error)
	// 获取订单详情
	GetOrder(oid uint64) (orders model.Order, err error)
	// 关闭数据库
	Close()
}

type shopService struct {
	log     *log.Logger
	rpo     repository.ShopRepo
	userSrv userSer.UserService
}

func NewService(log *log.Logger, rpo repository.ShopRepo, userSrv userSer.UserService) ShopService {
	s := &shopService{
		log:     log,
		rpo:     rpo,
		userSrv: userSrv,
	}
	return s
}

func (s *shopService) Close() {
	s.rpo.Close()
}
